﻿#region Using
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
#endregion Using

namespace LloydGame
{
    public class GameScreenComponent
    {
        #region Fields
        protected Game m_game;
        protected String m_title;
        protected SpriteFont m_normalfont;
        protected SpriteFont m_smallfont;
        protected SpriteBatch m_spritebatch;
        protected Vector2 m_pos, m_size;

        // State control
        protected bool m_active;

        protected Texture2D t_blanktex;
        #endregion Fields

        #region Properties
        public bool Active { get { return m_active; } set { m_active = value; } }
        //public bool KeyboardHover { get { return m_keyboardhover; } set { m_mousehover = false; m_keyboardhover = value; } }
        //public bool MouseHover { get { return m_mousehover; } set { m_mousehover = value; } }
        #endregion

        #region Constructor
        public GameScreenComponent(String p_title, Vector2 p_pos, Vector2 p_size, Game p_game)
        {
            m_game = p_game;
            m_title = p_title;
            m_normalfont = ((Game1)p_game).menuFontNormal;
            m_smallfont = ((Game1)p_game).menuFontSmall;
            m_spritebatch = new SpriteBatch(((Game1)p_game).GraphicsDevice);
            m_pos = p_pos;
            m_size = p_size;

            m_active = false;

            //t_blanktex = Texture2D.FromFile(((Game1)p_game).GraphicsDevice, "blank.png");
        }
        #endregion

        #region Draw
        public virtual void Draw(SpriteBatch p_spritebatch, bool p_active)
        {
            // Debug
            //if (p_mouseover)
            //    p_spritebatch.Draw(t_tex, new Rectangle((int)m_pos.X, (int)m_pos.Y, (int)m_size.X, (int)m_size.Y), Color.DimGray);

            // Render simple menutext
            p_spritebatch.DrawString(m_normalfont, m_title, new Vector2(m_pos.X + 1, m_pos.Y + 1), Color.Black);
            if (m_active)
                p_spritebatch.DrawString(m_normalfont, m_title, m_pos, Color.DimGray);
            else
                p_spritebatch.DrawString(m_normalfont, m_title, m_pos, Color.White);
        }
        #endregion

        #region HitTest
        public virtual void HitTest(Vector2 p_pos)
        {
            if (m_active)
                return;

            if (p_pos.X < m_pos.X)
            {
                m_active = false;
                return;
            }
            else if (p_pos.Y < m_pos.Y)
            {
                m_active = false;
                return;
            }
            else if (p_pos.X > m_pos.X + m_size.X)
            {
                m_active = false;
                return;
            }
            else if (p_pos.Y > m_pos.Y + m_size.Y)
            {
                m_active = false;
                return;
            }

            m_active = true;
        }
        #endregion
    }
}